<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Server_model Class 
 * 
 * @author Thy Ngoc
 */
class Server_model extends DataMapper {

    var $model = 'server_model';
    var $table = 'server';
    
    // --------------------------------------------------------------------
    // Construct
    // --------------------------------------------------------------------
    public function __construct($id="") {
    	parent::__construct($id);
    }
    
    // --------------------------------------------------------------------
    var $has_one = array();
    // --------------------------------------------------------------------
    var $validation = array();
    // --------------------------------------------------------------------
    /**
     * Default order in query select 
     */
    var $default_order_by = array('id');

    // --------------------------------------------------------------------
    /**
     * string value of object
     * 
     * @access private
     * @param null
     * @return string 
     */
    function __toString() {
        return empty($this->title) ? '---empty---' : $this->title;
    }

    // --------------------------------------------------------------------
    /**
     * string value of partner
     * 
     * @access public
     * @param null
     * @return string
     */
    function get_partner() {
        return $this->validation['partner']['values'][$this->partner];
    }

    // --------------------------------------------------------------------
    /**
     * string value of active
     * 
     * @access public
     * @param null
     * @return string
     */
    function get_active() {
        return $this->validation['active']['values'][$this->active];
    }

    // --------------------------------------------------------------------
    /**
     * string value of type
     * 
     * @access public
     * @param null
     * @return string
     */
    function get_type() {
        return $this->validation['type']['values'][$this->type];
    }

    // --------------------------------------------------------------------
    /**
     * array partner of object
     * 
     * @access public
     * @param bool
     * @return array
     */
    function partner_list($zero = FALSE) {
        $partner_list = $this->validation['partner']['values'];
        if ($zero) {
            $partner_list = array_merge(array('' => '--All--'), $partner_list);
        }
        return $partner_list;
    }

    // --------------------------------------------------------------------
    /**
     * array active of object
     * 
     * @access public
     * @param bool
     * @return array
     */
    function active_list($zero = FALSE) {
        $active_list = $this->validation['active']['values'];
        if ($zero) {
            $active_list = array_merge(array('' => '--All--'), $active_list);
        }
        return $active_list;
    }

    // --------------------------------------------------------------------
    /**
     * array active of object
     *
     * @access public
     * @param bool
     * @return array
     */
    function type_list($zero = FALSE) {
        $type_list = $this->validation['type']['values'];
        if ($zero) {
            $type_list = array_merge(array('' => '--All--'), $type_list);
        }
        return $type_list;
    }

    function merge_by_server($server){
        $this->select("merge");
        $this->where("name", $server);
        $this->get();
        return explode("-", $this->merge);
       //$this->merge
    }
    
    function get_list_server(){
        $this->select("name");
        return $this->get();
    }
    
    function total_server(){
        return $this->select("id")->count();
        //$this->check_last_query();
    }
    function get_list($select="name, merge, server"){
        $this->select();
        return $this->get();
    }
    // --------------------------------------------------------------------
    /**
     * array metadata for generate jquery grid. 
     * 
     * @access public
     * @param null
     * @return array
     */
    function jqgrid_metadata() {
        //edittype: 'text', 'textarea', 'select', 'checkbox', 'password', 'button', 'image', 'file', 'custom' 
        return array(
            'names' => array(
                'id',
                $this->localize_label('server'),
                $this->localize_label('name'),
            	$this->localize_label('partner'),
            	$this->localize_label('dns'),            	
                $this->localize_label('merge')
            ),
            'model' => array(
                array('name' => 'id', 'hidden' => TRUE, 'key' => TRUE,
                    'editrules' => array('edithidden' => TRUE)
                ),
                array('name' => 'title', 'width' => '300',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
                array('name' => 'name',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
                array('name' => 'dns',
                		'searchoptions' => array(
                				'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                		)
                ),
                array('name' => 'partner',
                		'searchoptions' => array(
                				'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                		)
                ),
                array('name' => 'merge',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
            )
        );
    }

}

/* End of file server.php */
/* Location: ./application/models/server.php */